using System;
using FU.Capstones.IMS.Web.Common;
using FU.Capstones.IMS.Web.Common.InventoryServiceProxy.DataContracts;
using FU.Capstones.IMS.Web.Common.InventoryServiceProxy.EventArgs;

namespace FU.Capstones.IMS.Web.Silverlight.Models
{
    public class UserInfoModel : ModelBase
    {
        public UserInfoModel()
        {
            client.GetSingleEmployeeCompleted += DoGetSingleEmployeeCompleted;
            client.ChangePasswordCompleted += DoChangePasswordCompleted;
            client.GetAuthorizationCollectionCompleted += DoGetAuthorizationCollectionCompleted;
        }

        #region ChangePassword

        public event EventHandler<FeedbackCompletedEventArgs> ChangePasswordCompleted;

        public int ChangePasswordAsync(NewPasswordData account)
        {
            client.ChangePasswordAsync(account);
            return WebConstants.MagicNumer;
        }

        void DoChangePasswordCompleted(object sender, FeedbackCompletedEventArgs e)
        {
            if (ChangePasswordCompleted != null)
            {
                ChangePasswordCompleted(sender, e);
            }
        }

        #endregion

        #region GetSinglEmployee

        public event EventHandler<SingleFeedbackCompletedEventArgs<Employee>> GetSingleEmployeeCompleted;

        public int GetSingleEmployeeAsync(int objectID)
        {
            client.GetSingleEmployeeAsync(objectID);
            return WebConstants.MagicNumer;
        }

        void DoGetSingleEmployeeCompleted(object sender, SingleFeedbackCompletedEventArgs<Employee> e)
        {
            if (GetSingleEmployeeCompleted != null)
            {
                GetSingleEmployeeCompleted(sender, e);
            }
        }

        #endregion

        #region GetAuthorizationCollection

        public event EventHandler<CollectionFeedbackCompletedEventArgs<Authorization>> GetAuthorizationCollectionCompleted;

        public int GetAuthorizationCollectionAsync()
        {
            client.GetAuthorizationCollectionAsync(false);
            return WebConstants.MagicNumer;
        }

        private void DoGetAuthorizationCollectionCompleted(object sender, CollectionFeedbackCompletedEventArgs<Authorization> e)
        {
            if (GetAuthorizationCollectionCompleted != null)
            {
                GetAuthorizationCollectionCompleted(sender, e);
            }
        }

        #endregion

    }
}